package com.freewater.library.catalogue.presentation;


import com.freewater.library.catalogue.application.BookCommandService;
import com.freewater.library.catalogue.presentation.request.CreateBookRequest;
import com.freewater.library.catalogue.presentation.request.UpdateBookRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/book")
@RequiredArgsConstructor
@Validated
public class BookController {

    private final BookCommandService bookCommandService;

    @PostMapping("/create-book")
    public void createBook(@Validated @RequestBody CreateBookRequest request) {
        this.bookCommandService.createBook(request.toCommand());
    }

    @PostMapping("/update-book")
    public void updateBook(@Validated @RequestBody UpdateBookRequest request) {
        this.bookCommandService.updateBook(request.getIsbn(), request.toCommand());
    }
}
